<?php
/**
 * 昭文社マップAPI
 */
class Rstdtl_MappleController extends Apm_Controller_Base
{
   	/**
	* 経路の距離を出力
	*/
	public function distanceAction()
	{
		//変数の宣言
		$response = "";

		//POSTパラメータの取得
		$this->_params = $this->getParameters();
		
		//URIの生成
		$uri = "http://route.chizumaru.com/WebService/route.asmx/rally?ticket=ASP";
		$uri .= "&k1=" . $this->_config['mappleapi']['k1'];
		$uri .= "&k2=" . $this->_config['mappleapi']['k2'];
		$uri .= "&rpt4=" . $this->_params['rpt4'];
		$uri .= "&rcnd=" . $this->_params['rcnd'];		
		$uri .= "&scl=" . $this->_params['scl'];
		$uri .= "&wid=" . $this->_params['wid'];
		$uri .= "&hei=" . $this->_params['hei'];
		$uri .= "&cs=" . $this->_params['cs'];
		
		//MappleAPIの実行
	    try{
			$s = @file_get_contents($uri);
			$xml = simplexml_load_string($s);
			
			// "$xml->rd"に経路の距離が設定されている
			if($xml->rd != null){
				$response =  number_format( (double) $xml->rd) . " m";
			}
			else{
				$response =  "- m";
			}
	    }catch(Exception $e){
	        $response =  "- m";
	    }
	    echo $response;
		$this->setXPassThroutgh();
		$this->display();
	}
}
?>
